﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using rbac.contracts.Dto.Output;
using rbac.contracts.Interface;
using rbac.domain.Entity;
using rbac.domain.Impl;
using rbac.domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rbac.services
{
    public class RoleService:ServiceBase,IRoleService
    {
        private readonly IRoleRepository _roleRepository;

        public RoleService(IRoleRepository roleRepository
            )
        {
            _roleRepository = roleRepository;
        }

        public int Add(RoleInput role)
        {
            var entity = _mapper.Map<Role>(role);
            entity.CreatedTime = DateTime.Now;
            entity.UpdateTime = DateTime.Now;
            entity.CreatedUserId = loginuserids;

            return _roleRepository.Add(entity);
        }
        public int Update(RoleInput role)
        {
            return _roleRepository.Update(_mapper.Map<Role>(role));
        }

        public List<RoleOutput> SearchRoles(string roleName)
        {
            var roles=_roleRepository.SearchRoles(roleName).Where(x=>x.IsDeleted==false);
            return _mapper.Map<List<RoleOutput>>(roles);
        }

        public int Delete(params int[] idlist)
        {
            var loginuserid = loginuserids;

            return _roleRepository.Delete(loginuserid, idlist);
        }
    }
}
